use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(Article::Table)
                    .if_not_exists()
                    .col(pk_auto(Article::Id))
                    .col(string(Article::Title).string_len(256))
                    .col(text(Article::Content))
                    .col(string(Article::SourceUrl).string_len(512))
                    .col(integer(Article::SpiderTaskId))
                    .col(text(Article::Breadcrumb))
                    .col(big_integer(Article::CreatedAt).not_null())
                    .col(big_integer(Article::UpdatedAt).not_null())
                    .to_owned(),
            )
            .await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .drop_table(Table::drop().table(Article::Table).to_owned())
            .await
    }
}

#[derive(DeriveIden)]
enum Article {
    Table,
    Id,
    Title,
    Content,
    SourceUrl,
    SpiderTaskId,
    Breadcrumb,
    CreatedAt,
    UpdatedAt
}
